package com.gxust.controller;

import com.gxust.dao.OrderDao;
import com.gxust.pojo.Address;
import com.gxust.service.AddressService;
import com.gxust.util.jwt.GetData;
import com.gxust.util.result.Result;
import com.gxust.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
 * 功能：地址添加的相关功能
 * 作者：zjk
 * 日期：2023/11/27 19:25
 */
@Slf4j
@RestController
@RequestMapping("/address")
@Api(tags = "地址管理")
public class AddressController {
    @Autowired
    private AddressService addressService;
    @GetMapping("/getAddress")
    @ApiOperation("查看地址")
    public Result getAddress(HttpServletRequest request){
        Integer userId = GetData.getUserId(request);
        List<Address> list = addressService.getAddress(userId);
        return Result.success(list);
    }

    /**
     * 新增地址
     * @param address
     * @param request
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加下单地址")
    public Result add(@RequestBody Address address, HttpServletRequest request){
        address.setUserId(GetData.getUserId(request));
        addressService.insertAddress(address);
        return Result.success();
    }
    /**
     * 删除地址
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    @ApiOperation("删除下单地址")
    public Result deleteById(Integer id){
        addressService.deleteById(id);
        return Result.success();
    }

    @PutMapping("/update")
    @ApiOperation("修改下单地址")
    public Result update(@RequestBody Address address){
        addressService.update(address);
        return Result.success();
    }
}